<template>
  <div class="container">
    <text class="big-title">示例</text>
    <div>
      <div class="btn" @click="test(0)"><text class="text">toast</text></div>
      <div class="btn" @click="test(1)"><text class="text">alert</text></div>
      <div class="btn" @click="test(2)"><text class="text">confirm</text></div>
      <div class="btn" @click="test(3)"><text class="text">prompt</text></div>
    </div>
    <text class="big-title">文档</text>
    <div class="button" @click="showDoc"><text class="btn-text">点击查看文档</text></div>
  </div>
</template>

<style scoped>
.container {
  padding: 10px;
}
.big-title {
  color: black;
  font-size: 50px;
  font-weight: bold;
  margin-bottom: 20px;
  margin-top: 20px;
}
.scroller {
  height: 400px;
}
.btn {
  border-radius: 8px;
  border-color: black;
  border-width: 2px;
  justify-content: center;
  align-items: center;
  padding-top: 25px;
  padding-bottom: 25px;
  margin-top: 20px;
  margin-bottom: 20px;
  background-color: transparent;
}
.btn:active {
  background-color: #ECECEC;
}
.cell {
  width: 100px;
  height: 100px;
  justify-content: center;
  align-items: center;
  background-color: #6699FF;
  margin: 2px;
  border-width: 2px;
  border-color: black;
}
.text {
  font-size: 30px;
}
.cell-text {
  font-size: 30px;
  color: white;
  font-weight: bold;
}
.button {
  height: 60px;
  justify-content: center;
  opacity: 1.0;
}
.button:active {
  opacity: 0.6;
}
.btn-text {
  font-size: 30px;
  color: blue;
}
</style>

<script>
  import utils from '../utils.js';
  let modal = weex.requireModule('modal');
  let navigator = weex.requireModule('navigator');
  export default {
    methods: {
      test(index) {
        switch(index) {
          case 0:
            modal.toast({message: 'this is a toast', duration: 1});
            break;
          case 1:
            modal.alert({message: 'this is an alert!', duration: 1});
            break;
          case 2:
            modal.confirm({message: 'this is a confirm!', duration: 1}, (value) => {
              modal.toast({message: 'you choose ' + value, duration: 1});
            });
            break;
          case 3:
            modal.prompt({message: 'please input your name:', duration: 1}, (value) => {
              if (value.result == 'Cancel') {
                modal.toast({message: 'Cancel!', duration: 1});
              } else {
                let content = value.data;
                if (content == '') {
                  modal.toast({message: 'Input nothing!', duration: 1});
                } else {
                  modal.toast({message: 'your input is: ' + value.data, duration: 1});
                }
              }
            });
            break;
        }
      },
      showDoc() {
        navigator.push({
          url: utils.getDocDetailUrl(weex.config.bundleUrl),
          animated: true
        });
      }
    }
  }
</script>
